ahham - Technical Training Estate module #1171
ahham - Technical Training Estate module #1171ahmedhamila wants to merge 12 commits intoodoo:19.0from
Conversation
|
@ahmedhamila Regarding your commits:
[1] https://www.odoo.com/documentation/master/contributing/development/git_guidelines.html |
[LINT] estate: add linting and formatting [IMP] estate: add estate_property model
4b9c7ca to
f37f977
Compare
| <field name="bedrooms"/> | ||
| <field name="living_area"/> | ||
| <field name="facades"/> | ||
| <filter name="Available Properties" domain="['|',('state','=','new'),('state','=','offer_received')]"/> |
There was a problem hiding this comment.
This can be a bit simpler:
| <filter name="Available Properties" domain="['|',('state','=','new'),('state','=','offer_received')]"/> | |
| <filter string="Available" name="available" domain="[('state', 'in', ('new', 'offer_received'))]"/> |
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| name = fields.Char(string="Title", required=True) | ||
| description = fields.Text(string="Description") |
There was a problem hiding this comment.
Just FYI (no need to change anything): if you don't specify a string parameter to a field, it will use the field name as string (and I believe it correctly converts underscores to spaces and capitalizes the first letter of each word). So if the string parameter and the field name are the same, you don't strictly need to specify it.
| description = fields.Text(string="Description") | |
| description = fields.Text() |
estate/models/estate_property.py
Outdated
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer") | ||
| salesman_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user) | ||
| property_tag_ids = fields.Many2many("estate.property.tag") |
There was a problem hiding this comment.
| property_tag_ids = fields.Many2many("estate.property.tag") | |
| property_tag_ids = fields.Many2many("estate.property.tag", string="Tags") |
| <field name="name"/> | ||
| </h1> | ||
| </div> | ||
| <field name="property_tag_ids" widget="many2many_tags"/> |
There was a problem hiding this comment.
Could you move this into the oe_title div?
estate/models/estate_property.py
Outdated
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for record in self: |
There was a problem hiding this comment.
It's slightly nicer to use a more descriptive name :) (same below)
| for record in self: | |
| for property in self: |
|
|
||
| @api.depends("validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: |
There was a problem hiding this comment.
Same here (and below)
| for record in self: | |
| for offer in self: |
| @api.depends("validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date: |
There was a problem hiding this comment.
This will prevent the deadline from being set when the record is being created. Could you use a fallback (e.g. today) if create_date isn't set yet? Same for the inverse method.
| validity = fields.Integer(string="Validity (days)", default=7) | ||
| date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline") | ||
|
|
||
| @api.depends("validity") |
|
FYI, if you scroll to the bottom of your PR, you'll find some Runbot links (i.e. the |
70036cc to
60becd9
Compare
estate/models/estate_property.py
Outdated
| else: | ||
| record.state = "cancelled" |
There was a problem hiding this comment.
No need for the else condition since there's a raise statement in the if (which shortcuts the method anyway):
| else: | |
| record.state = "cancelled" | |
| record.state = "cancelled" |
estate/models/estate_property.py
Outdated
| else: | ||
| record.state = "sold" |
There was a problem hiding this comment.
Same here:
| else: | |
| record.state = "sold" | |
| record.state = "sold" |
| for offer in record.property_id.offer_ids: | ||
| if offer != record: | ||
| offer.status = "refused" |
There was a problem hiding this comment.
Instead of this, you could refuse all offers (including the accepted one), before accepting the offer in question (as you do above):
record.property_id.offer_ids.status = "refused"But this line should be moved before the record.status = "accepted" statement.
This works because the ORM has special handling for recordsets: this line will set the status of all offers in the recordset to refused.
| if record.create_date and record.date_deadline: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| def action_accept_offer(self): |
There was a problem hiding this comment.
I guess you should also mark the property as having an accepted offer?
record.property_id.state = "offer_accepted"| return True | ||
| def action_refuse_offer(self): | ||
| for record in self: | ||
| record.status = "refused" |
There was a problem hiding this comment.
Maybe we should also update the related property, in case the offer was accepted and then refused? (it's a bit of an edge case though 😅 )
estate/models/estate_property.py
Outdated
| @api.constrains("selling_price") | ||
| def _check_selling_price_minimum_ratio(self): | ||
| for property in self: | ||
| if not property.selling_price: | ||
| continue | ||
| if float_compare(property.selling_price, property.expected_price * 0.9, precision_digits=2) < 0: | ||
| raise ValidationError("The selling price must be at least 90% of the expected price.") |
There was a problem hiding this comment.
Could you move these before the action methods? See also https://www.odoo.com/documentation/master/contributing/development/coding_guidelines.html#symbols-and-conventions
estate/models/estate_property.py
Outdated
| @api.constrains("selling_price") | ||
| def _check_selling_price_minimum_ratio(self): | ||
| for property in self: | ||
| if not property.selling_price: |
There was a problem hiding this comment.
This is a bit risky, it would be safer to use float_is_zero (which allows for precision errors).
a9e522a to
ef6a1a9
Compare
…perties page in form view
8c86fa6 to
a41e581
Compare
a41e581 to
5510c98
Compare

No description provided.